//
//  imageViewController.m
//  INAlienLand
//
//  Created by dllo on 15/7/4.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "imageViewController.h"
#import "HTTPTool.h"
#import "thanksCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "MJRefresh.h"
#import "bigImageViewController.h"

@interface imageViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic,retain)UICollectionView *cityCollect;
@property (nonatomic,retain)NSMutableArray *cityArr;


@end

@implementation imageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.cityArr = [NSMutableArray array];
    [self createData];
    [self createcollect];
    [self.cityCollect addFooterWithCallback:^{
        [self createData];
        [self.cityCollect footerEndRefreshing];
    }];
}
-(void)createcollect
{
    
    UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc]init];
    flowlayout.itemSize = CGSizeMake((self.view.frame.size.width-40)/3, (self.view.frame.size.height-150)/4);
    flowlayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    flowlayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    self.cityCollect = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-64-49) collectionViewLayout:flowlayout];
    [self.view addSubview:self.cityCollect];
    self.cityCollect.backgroundColor = [UIColor colorWithRed:0.960 green:0.968 blue:1.000 alpha:1.000];
    self.cityCollect.delegate = self;
    self.cityCollect.dataSource = self;
    [self.cityCollect registerClass:[thanksCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    }
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.cityArr.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    thanksCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    NSString *str = self.cityArr[indexPath.row];
//    //layer负责显示控件中的一些设置信息,比如边框,弧度等
//    //创建一个动画的效果
//    CATransition *transistio = [CATransition animation];
//    //设置动画的类型
//    transistio.type = @"rippleEffect";
//    
//    //    suckEffect（三角）
//    //
//    //    rippleEffect（水波抖动）
//    //
//    //    pageCurl（上翻页）
//    //
//    //    pageUnCurl（下翻页）
//    //
//    //    oglFlip（上下翻转）
//    
//    //设置动画的时长
//    
//    [transistio setDuration:3];
//    //设置动画的重复次数
//    [transistio setRepeatCount:1];
//    
//    //向imageview的layer里添加动画效果
//    [cell.cityImage.layer addAnimation:transistio forKey:@"rippleEffect"];
    [cell.cityImage sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"QQ登录"]];
    
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    bigImageViewController *bigImage = [[bigImageViewController alloc]init];
    [self.navigationController pushViewController:bigImage animated:YES];
    bigImage.arer = self.arer;
    bigImage.ww = indexPath.row;
}
-(void)createData
{
    static NSInteger i = 0;
    i=i+18;
   [HTTPTool get:[NSString stringWithFormat:@"http://api.breadtrip.com//destination/place/%@/%@/photos/?gallery_mode=1&count=%ld&",self.arer.type,self.arer.bId,i] body:nil HTTPResult:JSON success:^(id result) {
       NSDictionary *dic = result;
       NSArray *Arr =dic[@"items"];
       for (NSDictionary *tempDic in Arr) {
           NSString *str = tempDic[@"photo"];
           [self.cityArr addObject:str];
           
           
       }
       
       [self.cityCollect reloadData];
       NSLog(@"111");
   } failure:^(NSError *error) {
       
   }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
